<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use App\Ordinfo;

class ChangeaddrController extends Controller
{
    public function changeaddr(){
        Auth::user();
        $change=Ordinfo::orderBy("uid","desc")->get();
        return view("changeAddr",["change"=>$change]);
    }
    public function addPost(){
        $res=DB::table('ordinfos')->insert(['address'=>$_POST['address'] ,'mobile'=>$_POST['mobile']]);
        if($res){
            return redirect("changeaddr");
        }  
    }
    public function del($uid){
        $res=DB::table("ordinfos")->where("uid",$uid)->delete();
        if($res){
            return redirect("changeaddr");
        }
    }
    public function update($uid){
        if(empty($_POST)){
            $row=DB::table("ordinfos")->where("uid",$uid)->first();
            $ord=["ord"=>$row];
            return view("changeaddr.update",$ord);
        }else{
            $row=["address"=>$_POST["address"],"mobile"=>$_POST["mobile"]];
            $res=DB::table("ordinfos")->where("uid",$uid)->update($row);
            if($res){
                return redirect("changeaddr");
            }
        } 
    }
}
